Skip to content

Add optional zstd support - #232

Merged
noise64 merged 7 commits into
mainfrom
add-zstd
Nov 27, 2026
Merged

noise64 merged 7 commits into
mainfrom
add-zstd

Conversation

@noise64

@noise64 noise64 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
  • partial GOL-1947; ordinary-merged node-26-target at df908bf7, including main a57ed896 and folded Fix SQLite prepare and value contracts [skip ci] #231. Retargeted to main after Switch node_compat to Node 26.13.1 #218 landed at 2bc23cf9; main's tree equals the reviewed foundation, so the scoped diff and prospective merge tree are unchanged
  • adds optional zstd through zstd-safe 7.2.4 / reference libzstd 1.5.7, as selected by Dávid; included in full tiers, excluded from normal-p3, native workers disabled for WASI
  • supports public sync/callback/stream APIs, dictionaries, parameters, flush/reset, pledges and concatenated frames. Native output steps respect chunkSize and readable backpressure; convenience APIs enforce total maxOutputLength. Frame/reset semantics and explicit/finalizer ownership are preserved
  • fixes callback encoding, shared dictionaries and numeric parameters (LDM tri-state; flags normalize nonzero integers), callback cancellation/pledges and constructor rollback. The final five-gap repair keeps constructor-encoded output binary, snapshots info, preserves native error codes under patched intrinsics, adds direct ZSTD aliases and checks callbacks before input conversion
  • fixes the team's bytesWritten finding in df468ecd: accepted input is counted per native step, ignored junk counts zero, and already accepted partial prefixes count once. No ABI, frame/reset, error-policy or Reject trailing input across zlib codecs #239 branch changes; optional layout/visibility notes left unchanged
  • current local checks on merge 9df36e0a: build/all-target Clippy, formatting, five skeleton Clippy lanes, DTS 1, report contracts 11, stock/P3 runtime 4 (including 16 public contract groups), discovery 1, pristine Node26 zlib 73 passed / 250 ignored. Public-WASM regression was red on dc2 (18 !== 14) and green after the fix; identical Node26 controls pass. Accounting cases cover sync/callback/stream, split prefixes, concatenated/skippable frames and junk. No new test inventory or generated-output changes
  • both requested independent high-effort reviews clear the complete three-file dc2b6803..df468ecd accounting delta: observed GPT-6.1 Sol/high and Claude Opus 5.5/high, all three complete diffs covered, no actionable findings. These are read-only source reviews, not independently executed tests
  • integration self-review and the existing reviewer's completed exact-candidate assessment are clear: conflict-free ordinary merge, empty remerge diff, complete 13-file zstd patch unchanged against the new base. Native/wrapper/fixture/config/report blobs, including the accounting correction, are unchanged. Reviewer inspected validation logs and identity manifest; no source/evidence blocker, authored conflict resolution or new behavior/model-review round. Assessment retained as nov27-232-9df36e0a-local-integration rev2, desk50; this is not team approval or merge clearance
  • prior e3b93743..dc2b6803 dual-review clearance, df468ec corrected-code approval and whole-PR scoped agreement remain attributed to those candidates. Historical raw changes_required reviews and circuit-breaker history are retained
  • Exact-head 9df36e0a CI passed, attempt1: all 28 executed checks succeeded, including configured stock/fork optimizer, runtime, node-compat and Preview3 lanes. Proof and tag-only release/publish jobs were skipped, not passed; no release or deployment occurred
  • six additional mixed-codec diagnostic cases remain known gaps, not promoted; no vendored assertions changed. Shared foundation/SQLite entries and separate Reject trailing input across zlib codecs #239 Brotli source are preserved; only Reject trailing input across zlib codecs #239's exact discovery-test correction is reused. Feature-off zstd APIs remain discoverable throwing stubs
  • Vigoo approved the exact 9df36e0a head; no later PR comments were present at merge preflight. Dávid authorized merging after Switch node_compat to Node 26.13.1 #218 lands, with add-zstd preserved until Reject trailing input across zlib codecs #239 is retargeted. No duplicate review request or source change. No full compatibility-discovery campaign, broader option/getter/private-API parity, Golem durability/recovery, shipped release-size/performance/heap or optional-full licensing qualification claimed; configured CI success does not finish GOL-1947

Node compatibility

Compared with main at2bc23cf9 (base report identical to reviewed foundation df908bf/d3e9d832): primary 3200/4499 (71.1%) → 3228/4523 (71.4%); full public 3200/9654 (33.1%) → 3228/9654 (33.4%). Total 10794 unchanged. The repair promotes only the explicitly evaluated test-zlib-decode-strings.js case, after it passed with pristine Node26 assertions. The foundation update/retarget itself changes none of these counts.

Only 28 completely passing cases become runnable: ten prior gaps and 18 newly evaluated cases. Another six newly evaluated failures become known gaps; the primary denominator therefore increases by 24, not by excluding failures. zlib runnable 45 → 73, gaps 15 → 11, unevaluated 260 → 236, total 324 unchanged.

Matched debug component builds at initial source 6b5b62e4 differ only by the zstd feature: 31,434,664 vs 28,210,270 bytes (3,224,394 added bytes); re-enabling reproduced identical enabled bytes. Not repeated after the frame-accounting or current corrective repairs; this is historical evidence, not a release-size or memory measurement.

@noise64
noise64 marked this pull request as ready for review November 25, 2026 09:59
@noise64
noise64 marked this pull request as draft November 26, 2026 07:41
@noise64
noise64 marked this pull request as ready for review November 26, 2026 12:40

@vigoo vigoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed only this PR's delta against #231 (d3e9d83..dc2b680). One medium-severity public API defect and two optional convention notes follow. Verification used the actual Rust backend with zstd-safe 7.2.4 / libzstd 1.5.7 and the actual JS wrapper with Node stream/buffer adapters: 216 output/error comparisons against Node 26.13.1 matched, while separate byte-accounting probes reproduced the finding. This is not end-to-end WASI evidence; I did not rerun the full WASI/QuickJS suite locally. Exact-head CI was independently checked and is successful.


_processChunk(chunk, flush, limit = _getKMaxLength()) {
const data = toUint8Array(toBuffer(chunk));
this._bytesWritten += data.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium — DEFECT: bytesWritten includes ignored trailing junk.

This adds all supplied bytes, including input that the decoder discards after the compressed stream ends. _processStream repeats this at line 1266, and the native garbage branch also reports discarded bytes as consumed.

Reproducer: const frame = zlib.zstdCompressSync('hello'); const input = Buffer.concat([frame, Buffer.from('junk')]); const result = zlib.zstdDecompressSync(input, { info: true });

The frame is 14 bytes. Node 26.13.1 returns result.engine.bytesWritten === 14; this implementation returns 18. Both return hello. The same difference occurs through callback info: true and the stream API. Callers using this public property to locate the unconsumed suffix get the wrong boundary.

Please track codec-consumed bytes separately from bytes discarded to advance the input driver, preserving partial-prefix accounting, and add public regression cases for sync, callback, and streaming decompression with trailing junk. Simply summing the current native consumed return would still include the junk. Confidence: high; reproduced with the actual JS wrapper and Rust backend in the scoped native harness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in df468ecd. Both JS paths now add codec-consumed bytes to bytesWritten. The native trailing-junk branch returns consumed=0 and done=true, so the driver stops without counting discarded bytes. Buffered partial prefixes remain counted once. Public WASM regressions cover sync, callback and streaming decompression, including split junk, partial prefixes, concatenated and skippable frames, with pinned Node controls. The optional layout/visibility notes are unchanged.

use flate2::{Compression, Decompress, FlushDecompress, Status};

#[cfg(feature = "zstd")]
mod zstd;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low, nonblocking — MAINTAINABILITY/CONVENTION (CS-004). Adding this child module introduces the mixed zlib.rs + zlib/zstd.rs layout. The review convention calls for a directory module with zlib/mod.rs when a module has children. Consider using that layout; this is an optional organization note, not a correctness issue.

}

pub(super) fn new(
decompress: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low, nonblocking — MAINTAINABILITY/CONVENTION (CS-003). The new backend entry points use pub(super) (new, push, reset, and close). The review convention prefers private or pub instead of restricted visibility. Consider pub for these parent-called functions while keeping the backend module itself private. This is a convention note, not a functional defect.

@noise64 noise64 changed the title Add optional zstd support [skip ci] Add optional zstd support Nov 26, 2026
@noise64
noise64 requested a review from vigoo November 26, 2026 20:23
@noise64
noise64 changed the base branch from fix-sqlite-value-contracts to node-26-target November 27, 2026 13:01

@vigoo vigoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the own delta against the refreshed #218 base. The bytesWritten finding is resolved, including trailing junk and split-prefix accounting. No new blocking findings; the earlier visibility and module-layout notes remain optional. Local source-harness checks and inspected exact-head CI support this assessment; the full WASI/QuickJS suite was not rerun locally.

@noise64
noise64 changed the base branch from node-26-target to main November 27, 2026 14:30
@noise64
noise64 merged commit 2d3239f into main Nov 27, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants